package com.aleaho.cftrack.activity.tree;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.aleaho.cftrack.R;
import com.aleaho.cftrack.entity.DepartmentAndUser;
import com.github.johnkil.print.PrintView;
import com.unnamed.b.atv.model.TreeNode;

import org.w3c.dom.Text;

/**
 * @author Aleaho
 * @version 1.0
 * @date 2017/11/13
 * @desc
 */

public class IconTreeItemHolder extends TreeNode.BaseNodeViewHolder<IconTreeItemHolder.IconTreeItem> {


    private TextView tvValue;
    private PrintView arrowView;

    public IconTreeItemHolder(Context context) {
        super(context);
    }

    @Override
    public View createNodeView(final TreeNode node, IconTreeItem value) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.layout_icon_node, null);

        tvValue = (TextView) view.findViewById(R.id.node_value);
        tvValue.setText(value.text);

        final PrintView iconView = (PrintView) view.findViewById(R.id.icon);
        iconView.setIconText(context.getResources().getString(value.icon));

        arrowView = (PrintView) view.findViewById(R.id.arrow_icon);

        return view;
    }


    @Override
    public void toggle(boolean active) {
        arrowView.setIconText(context.getResources().getString(active ? R.string.icon_jiantouxia : R.string.icon_jiantouyou));
    }



    public static class IconTreeItem {
        public int icon;
        public String text;
        public DepartmentAndUser duEntity;


        public IconTreeItem(int icon, String text, DepartmentAndUser duEntity) {
            this.icon = icon;
            this.text = text;
            this.duEntity = duEntity;
        }
    }


}
